#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char **argv)
{
    fstream f("hello2.txt", ios::in | ios::trunc);
    if(!f)
    {
        cout << "file open error!" << endl;
    }

    ofstream f2("hello.txt", ios::out | ios::app);
    if(!f2)
    {
        cout << "file2 open error!" << endl;
    }

    fstream f3("hello3.txt", ios::out | ios::in | ios::app);
    if(!f3)
    {
        cout << "file3 open error!" << endl;
    }

    fstream f4;
    f4.open("hello4.txt", ios::in | ios::out | ios::app);
    if(!f4.is_open())
    {
        cout << "file4 open error!" << endl;
    }
    
    string data;
    //写数据
    cin >> data;
    f3.write(data.c_str(), data.size());
    f3 << data;
    
    char buffer[1024];
    //读数据
    data.clear();
    cout << f3.tellg() << endl;
    cout << f3.tellp() << endl;
    f3.seekg(0,ios::beg);
    //f3 >> data;
    f3.get(buffer,1024,'k');
    //cout << data << endl;
    cout << buffer << endl;
    char ch = f3.peek();
    if(ch == 'k')
    {
        f3.ignore(1);
        cout << "get k is stop!\n";
    }
    f3.get(buffer,1024,'k');
    //cout << data << endl;
    cout << buffer << endl;






    return 0;
}